package com.example.hello.reflect;

import java.lang.reflect.Field;

public class LoginImpl implements Login{
    @Override
    public String login(User user) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
        // 获取User类的user对象
        Class<?> clz = Class.forName("com.example.hello.reflect.User");
        Field usernameField = clz.getDeclaredField("username");
        usernameField.setAccessible(true);
        String username = (String)usernameField.get(user);
        Field userpsdField = clz.getDeclaredField("userpsd");
        userpsdField.setAccessible(true);
        String userpsd = (String)userpsdField.get(user);
        return username+" "+userpsd;
    }
}
